<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sets nonblocking mode for file descriptor fd</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.socket-set-nonblock" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">socket_set_nonblock</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">socket_set_nonblock</span> &mdash; <span class="dc-title">Sets nonblocking mode for file descriptor fd </span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.socket-set-nonblock-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>socket_set_nonblock</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$socket</code></span>
   ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   The <span class="function"><strong>socket_set_nonblock()</strong></span> function sets the 
   <strong><code>O_NONBLOCK</code></strong> flag on the socket specified by
   the <code class="parameter">socket</code> parameter.
  </p>
  <p class="para">
   When an operation (e.g. receive, send, connect, accept, ...) is performed on 
   a non-blocking socket, the script will not pause its execution until it receives a 
   signal or it can perform the operation. Rather, if the operation would result
   in a block, the called function will fail.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.socket-set-nonblock-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">socket</code></dt>

     <dd>

      <p class="para">
       A valid socket resource created with <span class="function"><a href="socket_create.html" class="function">socket_create()</a></span>
       or <span class="function"><a href="socket_accept.html" class="function">socket_accept()</a></span>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.socket-set-nonblock-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.socket-set-nonblock-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5607">
    <p><strong>Example #1 <span class="function"><strong>socket_set_nonblock()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$socket&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">socket_create_listen</span><span style="color: #007700">(</span><span style="color: #0000BB">1223</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">socket_set_nonblock</span><span style="color: #007700">(</span><span style="color: #0000BB">$socket</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">socket_accept</span><span style="color: #007700">(</span><span style="color: #0000BB">$socket</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>
     This example creates a listening socket on all interfaces on port 1223 and
     sets the socket to <strong><code>O_NONBLOCK</code></strong> mode. 
     <span class="function"><a href="socket_accept.html" class="function">socket_accept()</a></span> will immediately fail unless there is a
     pending connection exactly at this moment.
    </p></div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.socket-set-nonblock-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="socket_set_block.html" class="function" rel="rdfs-seeAlso">socket_set_block()</a> - Sets blocking mode on a socket resource</span></li>
    <li class="member"><span class="function"><a href="socket_set_option.html" class="function" rel="rdfs-seeAlso">socket_set_option()</a> - Sets socket options for the socket</span></li>
    <li class="member"><span class="function"><a href="stream_set_blocking.html" class="function" rel="rdfs-seeAlso">stream_set_blocking()</a> - 为资源流设置阻塞或者阻塞模式</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>